import { Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import {
  RoleModelData,
  RoleModelDataDocument,
} from './entities/role-model-datum.entity';
import { Model } from 'mongoose';

@Injectable()
export class RoleModelDataService {
  constructor(
    @InjectModel(RoleModelData.name)
    private schemaModel: Model<RoleModelDataDocument>,
  ) {}
  async findAll() {
    const data = await this.schemaModel.find().exec();
    return data.map((item) => ({
      ...item.toObject(),
      bagItems: new Map(item.bagItems),
      heroFormations: new Map(item.heroFormations),
      levelDataUids: new Map(item.levelDataUids),
    }));
  }

  findOne(id: number) {
    return this.schemaModel.findById(id);
  }

  remove(id: number) {
    return this.schemaModel.findByIdAndDelete(id);
  }
}
